package com.wtwd.device.controller;


import com.wtwd.device.constant.RespCode;
import com.wtwd.device.model.entity.HealthType;
import com.wtwd.device.model.entity.HealthTypeContent;
import com.wtwd.device.model.vo.ResultVO;
import com.wtwd.device.service.AppHealthTypeContentService;
import com.wtwd.device.service.AppHealthTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by mjy on 2023/8/16 14:33
 */
@Api(tags = "健康贴士")
@RestController
@RequestMapping("/health-tips")
public class HealthTipsController {

    @Resource
    private AppHealthTypeService healthTypeService;

    @Resource
    private AppHealthTypeContentService healthTypeContentService;

    /**
     * 分页查询健康类型
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "分页查询健康类型", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "当前页", required = true, dataType = "int")
            , @ApiImplicitParam(name = "pageSize", value = "页面大小", required = true, dataType = "int")
            , @ApiImplicitParam(name = "languageType", value = "语言类型", required = true, dataType = "String")
    })
    @GetMapping("/queryPage")
    public ResultVO<List<HealthType>> queryPage(@RequestParam(defaultValue = "1") Integer pageNo
            , @RequestParam(defaultValue = "10") Integer pageSize,
                                                @RequestParam("languageType") String languageType) {
        List<HealthType> healthTypes = new ArrayList<>();
        try {
            healthTypes = healthTypeService.queryPage(pageNo, pageSize, languageType);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.error();
        }
        return ResultVO.success(RespCode.SUCCESS, healthTypes);
    }


    /**
     * 根据健康类型id,分页查询健康内容
     *
     * @param pageNo
     * @param pageSize
     * @param typeId
     * @return
     */
    @ApiOperation(value = "根据健康类型id,分页查询健康内容", notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNo", value = "当前页", required = true, dataType = "int")
            , @ApiImplicitParam(name = "pageSize", value = "页面大小", required = true, dataType = "int")
            , @ApiImplicitParam(name = "typeId", value = "健康类型id", dataType = "int", required = true)
            , @ApiImplicitParam(name = "languageType", value = "语言类型", required = true, dataType = "String")
    })
    @GetMapping("/queryPageByTypeId")
    public ResultVO<List<HealthTypeContent>> queryPageByTypeId(@RequestParam(defaultValue = "1") Integer pageNo
            , @RequestParam(defaultValue = "10") Integer pageSize
            , @RequestParam(value = "typeId") Integer typeId, @RequestParam("languageType") String languageType) {
        List<HealthTypeContent> healthTypeContents = new ArrayList<>();
        if (typeId == null) {
            return ResultVO.error(RespCode.PARAMS_ERROR);
        }
        try {
            healthTypeContents = healthTypeContentService.queryPageByTypeId(pageNo, pageSize, typeId, languageType);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultVO.error();
        }
        return ResultVO.success(RespCode.SUCCESS, healthTypeContents);
    }


}
